//
//  TMGPatnerDetailViewController.m
//  TMGold
//
//  Created by Mac on 2017/12/11.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGPatnerDetailViewController.h"

@interface TMGPatnerDetailViewController ()
@property(nonatomic, strong) STLabel                     *desLable;
@property(nonatomic, strong) STSegementButton                     *segMent;
@property(nonatomic, strong) STButton                     *saveButton;/**< 存进 */
@end

@implementation TMGPatnerDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = _model.name;
   
    
    NSString * desStr = @"1.请携带本人身份证件\n2.仅可以选购店内的黄金产品\n3.通过黄金口袋账号余额可兑换店内千足金饰品详情请咨询合作金店\n4.如需使用黄金口袋进行黄金兑换，需线下支付兑换物品制作工费。5\n开具发票说明\n5.1)线下支付部分的金额，将有店铺或者商场开具.\n5.2)线下购金支付的部分金额，您可以在提取黄金产品后向黄金口袋索取，黄金口袋将为您免费寄送";
    
    NSString * cunjinDes = @"一、请携带以下物品前往门店办理存金手续\n1.存金人身份证\n2.已安装黄金口袋app的智能手机1台\n3.需要存储生息的实物黄金(如有黄金购置单据请携带)\n二、存金损耗说明如下:\n1、本专柜金条、黄金口袋金条: 无损耗\n2、投资金条、工艺金条: 无损耗\n3、足金及其以上成色金饰: 1%损耗";
    __weak typeof(self) weakSelf =  self;
    
    STSegementButton * segMent = [[STSegementButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44) andTitle:@[@"提金",@"存金"] handle:^(STSegementButton *sender) {
        if (weakSelf.segMent.cureentIndex == 0) {
            weakSelf.desLable.text = desStr;
            [weakSelf.saveButton setTitle:@"我要提金" forState:UIControlStateNormal];
            
        }else{
            weakSelf.desLable.text = cunjinDes;
             [weakSelf.saveButton setTitle:@"我要存金" forState:UIControlStateNormal];
        }
        UIView * header = weakSelf.tableView.tableHeaderView;
        [NSString lableAutoAdjustheightWithLabel:weakSelf.desLable];
        header.height = weakSelf.desLable.bottom + 20;
        weakSelf.tableView.tableHeaderView = header;
        [weakSelf.tableView reloadData];
    }];
    segMent.backgroundColor = [UIColor whiteColor];
    segMent.lineSelectedColor = TM_orangeColor;
    segMent.butTitleSelectedColor = TM_orangeColor;
    segMent.butTitleColor = TM_secendTextColor;
    segMent.lineColor = [UIColor whiteColor];
    segMent.cureentIndex = 0;
    segMent.autoMoveWithClic = YES;
    self.segMent = segMent;
    
     [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    header.backgroundColor = [UIColor whiteColor];
    
    UIImageView * bannerIamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 150)];
    bannerIamgeView.image = [UIImage imageNamed:@"10"];
    [bannerIamgeView sd_setImageWithURL:[NSURL URLWithString:_model.image] placeholderImage:nil];
    //bannerIamgeView.contentMode = UIViewContentModeScaleAspectFit;
    [header addSubview:bannerIamgeView];
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(15, bannerIamgeView.bottom + 20, 70, 70)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:35
                                           backgroundColor:nil
                                           backgroundImage:[UIImage imageNamed:@"9"]
                                                     image:nil];
    [iconButton sd_setBackgroundImageWithURL:[NSURL URLWithString:_model.image] forState:UIControlStateNormal];
    [header addSubview:iconButton];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right + 10, iconButton.top + 10, UIScreenWidth - 30 - 10 - iconButton.right, 18)
                                                     text:@"春熙路黄金"
                                                textColor:TM_firstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    titleLable.text = _model.name;
    [header addSubview:titleLable];
    
    STLabel * addLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right + 10, titleLable.bottom + 10, UIScreenWidth - 30 - 10 - iconButton.right, 18)
                                                     text:@"成都市春熙路IFS一楼12号"
                                                textColor:TM_secendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    addLable.text = _model.address;
    [header addSubview:addLable];
    __weak typeof(self) weakSelf =  self;
    STButton * phoneButton = [[STButton alloc] initWithFrame:CGRectMake(0, addLable.bottom  +0, 200, 44)
                                                     title:_model.mobile.description
                                                titleColor:TM_orangeColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    phoneButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    phoneButton.right = UIScreenWidth - 15;
    [phoneButton setClicAction:^(UIButton *sender) {
        NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",_model.mobile];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];
    [header addSubview:phoneButton];
    
    UIView * grawView = [[UIView alloc] initWithFrame:CGRectMake(0, phoneButton.bottom  +0, UIScreenWidth, 10)];
    grawView.backgroundColor = self.tableView.backgroundColor;
    [header addSubview:grawView];
    
    NSString * desStr = @"1.请携带本人身份证件\n2.仅可以选购店内的黄金产品\n3.通过黄金口袋账号余额可兑换店内千足金饰品详情请咨询合作金店\n4.如需使用黄金口袋进行黄金兑换，需线下支付兑换物品制作工费。5\n开具发票说明\n5.1)线下支付部分的金额，将有店铺或者商场开具.\n5.2)线下购金支付的部分金额，您可以在提取黄金产品后向黄金口袋索取，黄金口袋将为您免费寄送";
    
    NSString * cunjinDes = @"一、请携带以下物品前往门店办理存金手续\n1.存金人身份证\n2.已安装黄金口袋app的智能手机1台\n3.需要存储生息的实物黄金(如有黄金购置单据请携带)\n二、存金损耗说明如下:\n1、本专柜金条、黄金口袋金条: 无损耗\n2、投资金条、工艺金条: 无损耗\n3、足金及其以上成色金饰: 1%损耗";


    self.segMent.top =  grawView.bottom;
    [header addSubview:self.segMent];


    self.desLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.segMent.bottom  +10, UIScreenWidth - 20, 40)
                                                     text:desStr
                                                textColor:TM_secendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    self.desLable.numberOfLines = 0;
    [header addSubview:self.desLable];
    [NSString lableAutoAdjustheightWithLabel:self.desLable];
    
    header.height = self.desLable.bottom + 20;
    self.tableView.tableHeaderView = header;
    [self configFooter];
}
- (void)configFooter{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, 0, UIScreenWidth - 60 , 44)
                                                        title:@"我要提金"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:10
                                              backgroundColor:TM_orangeColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedLogoutButton];
    }];
    self.saveButton = confimButton;
    confimButton.st_centerY = 50;
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelectedLogoutButton{
    STActionSheet * action = [[STActionSheet alloc] initWithTitle:nil buttonTitles:@[@"在线客服",@"拨打电话"] cancelTitle:@"取消" delegate:self];
    [action show];
}

#pragma mark --STActionSheetDelegate
- (void)actionSheet:(STActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        [TMUtils gotoCustomServiceViewController];
    }
    if (buttonIndex == 1) {
        //拨打电话
        NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",serviceCustomPhpne];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
}
@end
